/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package G3.Mod;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 *
 * @author Dymion
 */
public class retrieveFS {

    File f;
    boolean exist;

    public retrieveFS() {
        try {
            //here we retrieve the actual formats
            Process p = Runtime.getRuntime().exec("su");
            DataOutputStream os = new DataOutputStream(p.getOutputStream());
            os.writeBytes("mount -o remount,rw /dev/block/stl9 /system\n");
            os.writeBytes("mount > /sdcard/Android/data/g3mod/temp.txt\n");
        } catch (IOException ex) {
            //we don't log anything
        }

        f = new File("/sdcard/Android/data/g3mod/temp.txt");
        exist = f.exists();
        if (exist) {
            try {
                FileInputStream fis = new FileInputStream(f);
                BufferedReader br = new BufferedReader(new InputStreamReader(fis));
                try {
                    for (int i = 1; i < 9; i++) // loop runned 9 times coz the data we need to extract is at 9th line
                    {
                        br.readLine();
                    }
                } catch (IOException ex) {
                    //we don't log anything
                }
            } catch (FileNotFoundException ex) {
                //we don't log anything
            }
        }
    }

    public String retrieveCache() {
        String cache = "";
        if (exist) {
            try {
                FileInputStream fis = new FileInputStream(f);
                BufferedReader br = new BufferedReader(new InputStreamReader(fis));
                try {
                    for (int i = 1; i < 11; i++) // loop runned 9 times coz the data we need to extract is at 9th line
                    {
                        br.readLine();
                    }
                    cache = (br.readLine()).substring(23, 27);
                } catch (IOException ex) {
                    //we don't log anything
                }
            } catch (FileNotFoundException ex) {
                //we don't log anything
            }
        }
        return cache;
    }

    public String retrieveSD() {
        String sd = "";
        if (exist) {
            try {
                FileInputStream fis = new FileInputStream(f);
                BufferedReader br = new BufferedReader(new InputStreamReader(fis));
                try {
                    for (int i = 1; i < 13; i++) // loop runned 9 times coz the data we need to extract is at 9th line
                    {
                        br.readLine();
                    }
                    sd = (br.readLine()).substring(34, 38);
                } catch (IOException ex) {
                    //we don't log anything
                }
            } catch (FileNotFoundException ex) {
                //we don't log anything
            }
        }
        return sd;
    }

    public String retrieveSystem() {
        String system = "";
        if (exist) {
            try {
                FileInputStream fis = new FileInputStream(f);
                BufferedReader br = new BufferedReader(new InputStreamReader(fis));
                try {
                    for (int i = 1; i < 9; i++) // loop runned 9 times coz the data we need to extract is at 9th line
                    {
                        br.readLine();
                    }
                    system = (br.readLine()).substring(24, 28);
                } catch (IOException ex) {
                    //we don't log anything
                }
            } catch (FileNotFoundException ex) {
                //we don't log anything
            }
        }
        return system;
    }

    public String retrieveData() {
        String data = "";
        if (exist) {
            try {
                FileInputStream fis = new FileInputStream(f);
                BufferedReader br = new BufferedReader(new InputStreamReader(fis));
                try {
                    for (int i = 1; i < 10; i++) // loop runned 9 times coz the data we need to extract is at 9th line
                    {
                        br.readLine();
                    }
                    data = (br.readLine()).substring(22, 26);
                } catch (IOException ex) {
                    //we don't log anything
                }
            } catch (FileNotFoundException ex) {
                //we don't log anything
            }
        }
        return data;
    }
}
